﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace FinalWeb
{
    public partial class ManagerLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRe_Click(object sender, EventArgs e)
        {
            this.txtZhang.Text = "";
            this.txtPwd.Text = "";
        }

        protected void Login_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112102;uid=2014112102;pwd=19960523;";
            SqlConnection cn = new SqlConnection(strCn);
            if (txtZhang.Text == "")
            {
                Response.Write(@"<script>alert('用户名不能为空！');</script>");
            }
            if (txtPwd.Text == "")
            {
                Response.Write(@"<script>alert('密码不能为空！');</script>");
            }
            try
            {
                cn.Open();
                string UserName = txtZhang.Text;
                string Password = txtPwd.Text;
                string strSql = "SELECT  ManagerName, ManagerPwd FROM  ManagerInfo WHERE   (ManagerName = @ManagerName) AND (ManagerPwd= @ManagerPwd)";
                SqlParameter[] parameters = { new SqlParameter("@ManagerName", UserName), new SqlParameter("@ManagerPwd", Password) };
                SqlCommand cmd = new SqlCommand(strSql, cn);
                cmd.CommandText = strSql;
                cmd.Parameters.AddRange(parameters);
                DataSet ds = new DataSet();
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(ds);
                DataTable table = ds.Tables[0];
                if (table != null)
                {
                    Response.Write(@"<script>alert('登录成功！');</script>");
                    Response.Redirect("ManagerMain.aspx");

                }
                else
                {

                    Response.Write(@"<script>alert('登录失败！请正确输入账号和密码');</script>");
                }
            }
            finally
            {
                cn.Close();
            }
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("index.aspx");
        }
    }
}